/**
 * Called before the form component is rendered.
 *
 * @param {JSRenderEvent} event the render event
 *
 * @properties={typeid:24,uuid:"4C92E680-FD58-4365-A805-9F71F1D1789A"}
 */
function onRenderImagen(event) {
	/** @type {JSRecord<db:/fwk_navigation_infocom/favoritos_usuario>}*/
	var $rcd = event.getRecord()
	if ($rcd)
		event.getRenderable().imageURL = $rcd.favoritos_usuario_to_pantallas.url_boton
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"F0126417-53B7-42CB-81B1-708021F4F163"}
 */
function elegirPantalla(event) {
	globals.gShow(pantalla_id)
}

/**
 * Callback method for when form is shown.
 *
 * @param {Boolean} firstShow form is shown first time after load
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"C2065405-39BB-43A3-AC42-6055DC756A62"}
 * @AllowToRunInFind
 */
function onShow(firstShow, event) {
	controller.find()
	solucion_id = globals.gIdSolucion
	controller.search()
	controller.sort('orden_aparicion asc')
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"29A46F5E-0864-400C-9C85-6C7BBD97A375"}
 */
function agregarFavorito(event) {
	if (globals.gIdFormActual)
	{
		var $sql = 'SELECT pantalla_id FROM favoritos_usuario WHERE usuario_id = ? AND pantalla_id = ?'
		var $args = [globals.gUsuarioID, globals.gIdFormActual]
		var $ds = databaseManager.getDataSetByQuery('fwk_navigation_infocom',$sql,$args,-1)
		if ($ds.getMaxRowIndex() != 0)
		{
			globals.DIALOGS.showInfoDialog('Aviso','La pantalla ya está marcada como favorito','OK')
			return
		}
	
		controller.newRecord()
		pantalla_id 	= globals.gIdFormActual
		usuario_id		= globals.gUsuarioID
		orden_aparicion = 1
		solucion_id		= globals.gIdSolucion
		userv_id		= globals.gUservID
		databaseManager.saveData(foundset.getRecord(foundset.getSelectedIndex()))
	}
	else
	{
		globals.DIALOGS.showWarningDialog('Aviso','Por favor, marque una pantalla antes de agregar a favoritos','OK')
	}
}
